/*
	取消Buff的处理程序
*/

package net.sf.odinms.net.channel.handler;

import net.sf.odinms.client.ISkill;
import net.sf.odinms.client.MapleBuffStat;
import net.sf.odinms.client.MapleCharacter;
import net.sf.odinms.client.MapleClient;
import net.sf.odinms.client.SkillFactory;
import net.sf.odinms.client.skills.*;
import net.sf.odinms.net.AbstractMaplePacketHandler;
import net.sf.odinms.net.MaplePacketHandler;
import net.sf.odinms.server.MapleStatEffect;
import net.sf.odinms.tools.data.input.SeekableLittleEndianAccessor;
import net.sf.odinms.tools.MaplePacketCreator;

public class CancelBuffHandler extends AbstractMaplePacketHandler implements MaplePacketHandler {

    @Override
    public void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
        int sourceid = changeSkillId(slea.readInt(), c.getPlayer());//技能ID
        MapleStatEffect effect;
        ISkill skill = SkillFactory.getSkill(sourceid);
        if (sourceid == 弓手.暴风箭雨
                || sourceid == 枪手.金属风暴
                || sourceid == 勇士.磁石
              /*|| skillId == 1221001 圣骑士磁石取消*/
                || sourceid == 龙骑.磁石
                || sourceid == 火毒.创世之破
                || sourceid == 冰雷.创世之破
                || sourceid == 牧师.创世之破
                || sourceid == 火毒.末日烈焰
                || sourceid == 刀飞.转化术
                || sourceid == 弩手.穿透箭
                || sourceid == 拳手.贯骨击
                || sourceid == 奇袭者.贯骨击
                || sourceid == 枪手.投弹攻击
                || sourceid == 夜行者.毒炸弹
                || sourceid == 风灵使者.暴风箭雨
                || sourceid == 龙神.冰点寒气 //冰点寒气
                || sourceid == 龙神.火焰喷射 //火焰喷射
                || sourceid == 双刀.终极斩  //终极斩
                || sourceid == 双刀.怪物炸弹  //怪物炸弹
                || sourceid == 弩骑.吞噬 //弩骑 吞噬
                || sourceid == 弩骑.奥义箭乱舞 //弩骑 奥义箭乱舞
                || sourceid == 机械师.火焰喷射器 //火焰喷射器
                || sourceid == 机械师.强化火焰喷射器
                ) {
            c.getPlayer().getMap().broadcastMessage(c.getPlayer(), MaplePacketCreator.skillCancel(c.getPlayer(), sourceid), false);
        }
        effect = skill.getEffect(1);
        if(sourceid == 战神.矛连击强化) {
            if(c.getPlayer().getBuffedValue(MapleBuffStat.矛连击强化) != null) 
                c.getPlayer().cancelEffect(effect, false, -1);
            //System.out.println("取消矛连击强化/人物Combo清0");
            c.getPlayer().setCombo(0);
        } else {
            //System.out.println("取消的技能id是："+sourceid);
            //System.out.println("取消的技能名字是："+SkillFactory.getSkillName(sourceid));
        }
        c.getPlayer().cancelEffect(effect, false, -1);
    }
    
    public int changeSkillId(int skillid, MapleCharacter chr) {
        int a = skillid;
        /*if(skillid == 机械师.金属机甲_重机枪 && chr.getBuffedValue(MapleBuffStat.机械师) != null)
            a = 机械师.金属机甲_重机枪;
        else */if(skillid == 战法.黑暗灵气 && chr.getSkillLevel(战法.进阶黑暗灵气) > 0)
            a = 战法.进阶黑暗灵气;
        else if(skillid == 战法.蓝色灵气 && chr.getSkillLevel(战法.进阶蓝色灵气) > 0)
            a = 战法.进阶蓝色灵气;
        else if(skillid == 战法.黄色灵气 && chr.getSkillLevel(战法.进阶黄色灵气) > 0)
            a = 战法.进阶黄色灵气;
        return a;
    }
}